﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
using XLua;
[LuaCallCSharp]
public class ButtonLua
{
    private static Button m_transform;
    private static Dictionary<uint, List<Action>> dicCallBack = new Dictionary<uint, List<Action>>();

    public static void On(uint skinID)
    {
        GameObject go = ObjectManager.Instance.GetGameObject(skinID);
        if (go != null)
        {
            m_transform = go.GetComponent<Button>();
        }
    }

    public static void Off()
    {
        m_transform = null;
    }

    public static void AddListener(uint skinID, Action callback)
    {
        On(skinID);
        AddListener(callback);
    }

    public static void AddListener(Action callback)
    {
        if (m_transform == null) return;
        //m_transform.onClick.AddListener
        ButtonClick.AddClickListener(m_transform, callback);
    }

    public static void RemoveListener(uint skinID, Action callback)
    {
        On(skinID);
        RemoveListener(callback);
    }

    public static void RemoveListener(Action callback)
    {
        if (m_transform == null) return;
        ButtonClick.RemoveClickListener(m_transform, callback);
    }
}

